# config/settings.py

import os
from typing import Dict, List
try:
    from pydantic_settings import BaseSettings
except ImportError:
    from pydantic import BaseSettings

class Settings(BaseSettings):
    """主配置文件"""
    
    # --- 项目基本信息 ---
    PROJECT_NAME: str = "多模态RAG系统"
    VERSION: str = "1.0.0"
    DEBUG: bool = True
    
    # --- Milvus 数据库设置 ---
    MILVUS_HOST: str = "10.3.244.23"
    MILVUS_PORT: str = "19530"
    MILVUS_COLLECTION: str = "rag_documents_v1"
    MILVUS_COLLECTION_IMAGE: str = "rag_images_v1"
    
    # --- 阿里云 OSS 账号信息 ---
    ALIYUN_OSS_ACCESS_KEY_ID: str = "LTAI5tLm9VNHqQG2w6p2ceJj"
    ALIYUN_OSS_ACCESS_KEY_SECRET: str = "TxZMYPzxh5krlNwSlMmLdJiDdQ8Uok"
    ALIYUN_OSS_BUCKET_DATASET: str = "dataset-square-migrate"
    ALIYUN_OSS_BUCKET_STUDY: str = "study-square-migrate"
    ALIYUN_OSS_REGION: str = "oss-cn-beijing"
    
    # --- 百炼RAG账号信息 ---
    BAILIAN_API_KEY: str = "sk-38b9daad5d5e46f690545046695bd6ff"
    BAILIAN_USER: str = "ehaihong@1773431696074921.onaliyun.com"
    BAILIAN_PASSWORD: str = "Bupt@2024"
    BAILIAN_URL: str = "https://bailian.console.aliyun.com"
    
    # --- 嵌入模型设置 ---
    EMBEDDING_MODEL: str = 'text-embedding-v4'
    MULTIMODAL_EMBEDDING_MODEL: str = 'multimodal-embedding-v1'
    VECTOR_DIMENSION: int = 1536
    IMAGE_VECTOR_DIMENSION: int = 1024
    
    # --- 阿里云API配置 ---
    ALIYUN_EMBEDDING_API_URL: str = "https://dashscope.aliyuncs.com/api/v1/services/embeddings/text-embedding-v4/text-embedding"
    ALIYUN_MULTIMODAL_API_URL: str = "https://dashscope.aliyuncs.com/api/v1/services/embeddings/multimodal-embedding-v1/text-image-embedding"
    
    # --- 文本切分设置 ---
    CHUNK_SIZE: int = 250
    CHUNK_OVERLAP: int = 50
    
    # --- 大语言模型设置 ---
    LLM_MODEL: str = "qwen-turbo-latest"
    LLM_API_KEY: str = BAILIAN_API_KEY
    LLM_API_URL: str = "https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions"
    
    # --- RAG (检索增强生成) 设置 ---
    TOP_K: int = 10
    SIMILARITY_THRESHOLD: float = 0.5
    
    # --- 文件上传配置 ---
    UPLOAD_FOLDER: str = "data/uploads"
    MAX_FILE_SIZE: int = 100 * 1024 * 1024  # 100MB
    ALLOWED_EXTENSIONS: Dict[str, List[str]] = {
        'text': ['.txt', '.md', '.csv'],
        'document': ['.pdf', '.docx', '.pptx'],
        'image': ['.jpg', '.jpeg', '.png', '.bmp', '.gif'],
        'video': ['.mp4', '.avi', '.mov', '.mkv']
    }
    
    # --- 任务状态 ---
    TASK_STATUS_PENDING: str = "pending"
    TASK_STATUS_PROCESSING: str = "processing"
    TASK_STATUS_COMPLETED: str = "completed"
    TASK_STATUS_FAILED: str = "failed"
    
    # --- API设置 ---
    API_HOST: str = "0.0.0.0"
    UPLOAD_API_PORT: int = 8000
    RAG_API_PORT: int = 8001
    
    # --- 日志配置 ---
    LOG_LEVEL: str = "INFO"
    LOG_FORMAT: str = "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
    LOG_FILE: str = "data/logs/app.log"
    
    class Config:
        env_file = ".env"
        case_sensitive = True
        extra = "ignore"  # 忽略额外的环境变量

# 创建全局设置实例
settings = Settings() 